class CarouselsController < ApplicationController
  before_action :set_carousel, only: [:edit, :update, :destroy]

  def index
    @html_title = '轮显图列表'
    @carousels = Carousel.all.order('order_num asc')
  end

  def new
    @html_title = '新建轮显图'
    @carousel = Carousel.new
  end

  def create
    @carousel = Carousel.new(carousel_params)
    respond_to do |format|
      if @carousel.save
        format.html {redirect_to carousels_path, notice: '创建成功！'}
      else
        format.html {render 'new'}
      end
    end
  end

  def edit
    @html_title = '编辑轮显图'
  end

  def update
    respond_to do |format|
      if @carousel.update(carousel_params)
        format.html {redirect_to carousels_path, notice: '更新成功！'}
        format.json {render json: 'success'.to_json}
      else
        format.html {render 'edit'}
      end
    end
  end

  def destroy
    @carousel.destroy
    redirect_to carousels_path, notice: '删除成功！'
  end

  private

  def set_carousel
    @carousel = Carousel.find(params[:id])
  end

  def carousel_params
    params[:carousel].permit!
  end

end
